using System;
using Object = UnityEngine.Object;

namespace LFromeWork
{
    public class ResourcesManager : IDisposable
    {
        /// <summary>
        /// 资源依赖信息 管理器
        /// </summary>
        public AssetInfoManager AssetInfo { get; private set; }

        public AssetLoader AssetLoader { get; private set; }
        public AssetBundleLoader AssetBundleLoader { get; private set; }

        public ResourcesManager()
        {
            AssetInfo = new AssetInfoManager();
            AssetBundleLoader = new AssetBundleLoader();
            AssetLoader = new AssetLoader();
        }

        internal void OnUpdate()
        {
            AssetLoader.OnUpdate();
            AssetBundleLoader.OnUpdate();
        }
        
        public void LoadAssetAsync(string assetFullPath, Action<string, Object> onLoadAssetComplete)
        {
#if EDITORLOAD && UNITY_EDITOR
            AssetLoader.LoadAssetEditor(assetFullPath,onLoadAssetComplete);
#else
            AssetLoader.LoadAssetAsync(assetFullPath,onLoadAssetComplete);
#endif
        }
        
        public void ReleaseAsset(string assetFullPath,Action<string, Object> onLoadAssetComplete)
        {
#if EDITORLOAD && UNITY_EDITOR
            AssetLoader.ReleaseAssetEditor(assetFullPath);
#else
            AssetLoader.ReleaseAsset(assetFullPath,onLoadAssetComplete);
#endif
        }
        
        public void Dispose()
        {
            AssetInfo.Dispose();
            AssetLoader.Dispose();
            AssetBundleLoader.Dispose();
        }
    }

}